//
//  MovieListView.swift
//  SwiftUi
//
//  Created by xm on 05/09/2025.
//

import SwiftUI

struct AnimesListView: View {
    let viewModel: AnimesViewModel
    init(viewModel: AnimesViewModel) {
        self.viewModel = viewModel
    }
    
    var body: some View {
        
        List {
            ForEach(viewModel.animes, id:\.id){ anime in
                Text("动漫 \(anime.name)")
                .onTapGesture {
                    viewModel.didSelect(anime: anime)
                }
            }
        }.task {
            await viewModel.fetch()
        }
    
    }
}

#Preview {
    let coordinator = AnimesCoordinator()
    let viewModel = AnimesViewModel( coordinator: coordinator)
    AnimesListView(viewModel: viewModel)
}
